package com.example.demo.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author zhaiding
 * @since 2019/5/3
 */
@Component
@Slf4j
public class TaskTest {

    /**
     * <p>
     * http://cron.qqe2.com/
     * cron 表达式收成器
     * </p>
     * 从 0 秒开始,每 1 秒执行一次
     *
     * @ Async 异步执行
     */
    @Async
    @Scheduled(cron = "* * * * * ?")
    public void task() {
        System.err.println(Thread.currentThread().getName() + " 执行时间" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }

}
